package com.wlanauth.dao.manage.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;

import com.wlanauth.dao.common.impl.CommonDaoImpl;
import com.wlanauth.dao.manage.UserDao;
import com.wlanauth.domain.manage.User;

public class UserDaoImpl extends CommonDaoImpl<User> implements UserDao {
	

	public User getByUsername(String username) throws DataAccessException {
		String hql = "from User u where u.username='%s'";
		@SuppressWarnings("unchecked")
		List<User> list = this.getHibernateTemplate().find(String.format(hql, username));
		if(list == null || list.size()<1) return null;
		if(list.size()>1){
			throw new RuntimeException("业务数据错误!期待返回最多1个结果,实际返回结果数:"+list.size());
		}
		return list.get(0);
	}

	public User getByBindIP(String bindIP) throws DataAccessException {
		String hql = "from User u where u.bindIP='%s'";
		@SuppressWarnings("unchecked")
		List<User> list = this.getHibernateTemplate().find(String.format(hql, bindIP));
		if(list == null || list.size()<1) return null;
		if(list.size()>1){
			throw new RuntimeException("业务数据错误!期待返回最多1个结果,实际返回结果数:"+list.size());
		}
		return list.get(0);
	}
	
	
}
